<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>多级对象解构</title>
</head>

<body>
  <script>
    // ============================== 多级对象解构 ==============================
    // 练习 1：要求把所有家庭成员解构出来
    const pig = {
      name: '佩奇',
      family: {
        mother: '猪妈妈',
        father: '猪爸爸',
        sister: '乔治'
      },
      other: {
        mother: '猪1',
        father: '猪2',
        sister: '乔3'
      },
      age: 6
    }
    
    // const {name,family:{mother,father,sister},other:{mother:m2,father:f2,sister:s2},age}=pig
    // console.log(name,mother,father,sister,m2,f2,s2,age)

    // 练习2：要求把所有家庭成员解构出来
    const arr = [
      {
        name: '佩奇',
        family: {
          mother: '猪妈妈',
          father: '猪爸爸',
          sister: '乔治'
        },
        age: 6
      }
    ]
    const[{name,family:{mother,father,sister},age}]=arr
    console.log(name,mother,father,sister,age)
  </script>
</body>

</html>